package com.example.demo01.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.demo01.R;
import com.example.demo01.entity.BxiaoQiGroup;

import java.util.List;

public class HttpResultAdapter extends BaseAdapter {
    private Context context;
    private List<BxiaoQiGroup> list;

    public HttpResultAdapter(List<BxiaoQiGroup> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public BxiaoQiGroup getItem(int index) {
        return list.get(index);
    }

    @Override
    public long getItemId(int index) {
        return list.get(index).getId();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater
                    .from(context)
                    .inflate(R.layout.item_list_http, parent, false);
            holder = new ViewHolder();
            holder.tv_http_item_id = convertView.findViewById(R.id.tv_http_item_id);
            holder.tv_http_item_name = convertView.findViewById(R.id.tv_http_item_name);
            holder.tv_http_item_time = convertView.findViewById(R.id.tv_http_item_time);
            holder.iv_http_item_img = convertView.findViewById(R.id.iv_http_item_img);
            convertView.setTag(holder);
        }
        if (holder != null) {
            BxiaoQiGroup item = list.get(position);
            holder.tv_http_item_id.setText(item.getId() + "");
            holder.tv_http_item_name.setText(item.getName());
            holder.tv_http_item_time.setText(item.getCreatedate().toString());
//            holder.iv_http_item_img.setImageURI(Uri.parse(item.getIco()));
            Glide.with(context)
                    .load(item.getIco())
                    .into(holder.iv_http_item_img);
        }

        return convertView;
    }

    static class ViewHolder {
        TextView tv_http_item_id, tv_http_item_name, tv_http_item_time;
        ImageView iv_http_item_img;

    }
}
